Ext.ns("fav");

fav.panel = {};
fav.panel.make = {
	list	: function(){},
};

fav.data = {};

fav.statics = {};
fav.statics.storagename = 'zpyr.carcenter_app.favorites';
fav.statics.defaultOpt = eval(getCategoryInfo('json' , '' , '' , '' , { 'category_gubun' : 'c001' }));

fav.statics.storageitem = function(){
	this.info_seq = '';
	this.name = '';
	this.category1 = '';
};

fav.statics.init = function() {
	fav.statics.favorites = new com.zpyr.StorageList( fav.statics.storagename );
};


fav.statics.category1Btns = function() {
	var items = [];
	items[0] = {
		xtype: 'spacer',
	};
	items[1] = {
        xtype: 'button',
        text :  '전체',
        handler: function() {
        	var dataList = fav.statics.favorites.getListByArray();
        	
        	var nArr = new Array();
			
			for( i in dataList) {
				if(typeof dataList[i] == 'object' ) {
					nArr.push(  JSON.parse( JSON.stringify(dataList[i])) );
				}
			}
			fav.data.ciStore.loadData(nArr);
        }
	};
	
	var i = 2;
	
	$(fav.statics.defaultOpt).each(function(){
		items[i] = {
			xtype: 'button',
			text : this.text,
			value : this.value,
			handler : function() {
			//	fav.data.ciStore.loadData( getCarcInfo('json' , '' , '' , '' , { 'category1' : this.value }) );
				var dataList = fav.statics.favorites.getListByArray();
				
				var nArr = new Array();
				
				for( i in dataList) {
					if(typeof dataList[i] == 'object' ) {
						if(dataList[i].category1 == this.value) {
							nArr.push(  JSON.parse( JSON.stringify(dataList[i])) );
						}
					}
				}
				fav.data.ciStore.loadData(nArr);
				
			}
		};
		i++;
	});
	items[i] = {
		xtype: 'spacer',
	};
	
	return items;
};

fav.panel.make.list = function(reload) {
if(reload == undefined) reload = true;
	
	if( !fav.panel.list || (fav.panel.list && reload) ) {
		//페널이 없거나, 페널이 있는데 리로드 해야되거나
		if(fav.panel.list) fav.panel.list.destroy();
		
		var itemTemplate = new Ext.XTemplate(
				'<div style="font-size:12px;">{name}</div>'		
		);
		
		var dataObj; 
		dataObj = JSON.parse( JSON.stringify( fav.statics.favorites.getListByArray() ) );
		
		fav.data.ciStore = new Ext.data.Store({
			model: 'carc_info',
			data : dataObj
		});
		
		var carc_list = new Ext.List({
			fullscreen:true,
			itemTpl: itemTemplate,
			store : fav.data.ciStore,
			draggable : true,
			onItemDisclosure : function(record , btnDom , index){
				map.panel.make.carcenter(  getCarcInfo('xml' , '' , '' , '' , { 'info_seq' : record.data.info_seq })  );
			},
		});
		
		
		fav.panel.list = new Ext.Panel({
			dockedItems : [
			               {
			            	   dock: 'top',
			            	   xtype: 'toolbar',
			            	   title: '<label style="font-size:14px">즐겨찾기</label>',
			               },
			               {
				       			dock: 'top',
				       			centered : true,
				       			xtype: 'toolbar',
				       			style : 'background:#feddaa;',
				       			items: fav.statics.category1Btns(),
			       			}
			],
			layout: {
				type: 'vbox',
				align: 'stretch',
				pack: 'center',
			},
			items : carc_list,
			
			
		});
	}
};
